package com.bookocean.infrastructure.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Jackson 配置类
 * 
 * @author BookOcean
 * @since 2024-01-01
 */
@Configuration
public class JacksonConfig {

    /**
     * 自定义 Jackson ObjectMapper 构建器
     */
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        return builder -> {
            // 注册 JavaTimeModule 来处理 Java 8 日期时间类型
            builder.modules(new JavaTimeModule());
            
            // 禁用将日期写为时间戳
            builder.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
            
            // 设置日期格式 - 只显示年月日
            builder.simpleDateFormat("yyyy-MM-dd");
        };
    }
}
